﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using BusinessLayer.WorldArtPrice.Entities;
using DBHelper;

namespace BusinessLayer.WorldArtPrice
{
    public class ContentTypeBL
    {
        private readonly DbHelper _db;

        public ContentTypeBL()
        {
            _db = new DbHelper(new DbConfig().DbWorldArtPriceConnectionString);         
        }

        public ContentType GetById(int id)
        {
            var oCommand = new SqlCommand("sp_ContentType_Select_By_Id") { CommandType = CommandType.StoredProcedure };
            oCommand.Parameters.Add(new SqlParameter("@Id", id));

            var list = _db.GetList<ContentType>(oCommand);
            return list.FirstOrDefault();
        }

        public List<ContentType> GetAll()
        {
            var oCommand = new SqlCommand("sp_ContentType_Select_All") { CommandType = CommandType.StoredProcedure };            

            var list = _db.GetList<ContentType>(oCommand);
            return list;
        }

        public void Insert(ContentType contentType)
        {
            var oCommand = new SqlCommand("sp_ContentType_Insert") { CommandType = CommandType.StoredProcedure };
            oCommand.Parameters.Add(new SqlParameter("@ContentTypeName", contentType.ContentTypeName));
            _db.ExecuteNonQuery(oCommand);            
        }

        public void Update(ContentType contentType)
        {
            var oCommand = new SqlCommand("sp_ContentType_Update") { CommandType = CommandType.StoredProcedure };
            oCommand.Parameters.Add(new SqlParameter("@Id", contentType.Id));
            oCommand.Parameters.Add(new SqlParameter("@ContentTypeName", contentType.ContentTypeName));
            _db.ExecuteNonQuery(oCommand);
        }

        public void Delete(int id)
        {
            var oCommand = new SqlCommand("sp_ContentType_Delete") { CommandType = CommandType.StoredProcedure };
            oCommand.Parameters.Add(new SqlParameter("@Id", id));            
            _db.ExecuteNonQuery(oCommand);
        }
    }
}
